# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
from pymongo import MongoClient
import time

client = MongoClient(host="localhost", port=27017)

db = client["自己笔记本上爬取阳光政务问政"]
collection = db[time.strftime("%Y-%m-%d")]


class SunpoliticPipeline:
    def process_item(self, item, spider):
        print(item)
        collection.insert(dict(item))
        print(f"爬虫的名字是{spider.__class__.__name__}")
        return item

    def open_spider(self, spider):
        spider.hello = "world"
